﻿using gt.framework.Configuration.ConfigEntity;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace gt.framework.Configuration
{
    [XmlRoot("configManager", Namespace = ConfigConstants.DefaultConfigNamespace)]
    public class ConfigManagerConfig : ManagerConfigBase
    {
        [XmlElement("subConfig")]
        public List<SubConfigEntry> ConfigEntrys { get; set; }

        public override string GetConfigPath(string configKey)
        {
            IEnumerable<SubConfigEntry> chooseItems = this.ConfigEntrys.Where<SubConfigEntry>(e => e.Name.ToUpper() == configKey.ToUpper());
            if (chooseItems != null && chooseItems.Count() > 0)
                return chooseItems.First().Path;

            return null;
        }
    }

    public class SubConfigEntry
    {
        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlAttribute("path")]
        public string Path { get; set; }
    }
}
